package com.demo2do.fms.admin.web.controller.data.business;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.demo2do.core.entity.page.Page;
import com.demo2do.core.web.interceptor.MenuSetting;
import com.demo2do.fms.admin.service.DataService;
import com.demo2do.fms.admin.utils.FormatUtils;
import com.demo2do.fms.admin.web.view.ExcelTemplateView;
import com.demo2do.fms.entity.data.business.OtherFeeType;

/**
 * 其他类型费用管理
 * 
 * @author Wy
 *
 */
@Controller
@RequestMapping("/other-fee-types")
@MenuSetting("menu-data")
public class OtherFeeTypeController {

    @Autowired
    @Qualifier("dataService")
    private DataService<OtherFeeType> otherFeeTypeService;

    /**
     * 
     * @param page
     * @return
     */
    @RequestMapping(value = "", method = RequestMethod.GET)
    @MenuSetting("submenu-other-fee-type")
    public ModelAndView list(Page page) {

        ModelAndView modelAndView = new ModelAndView("data/business/other-fee/other-fee-type-list");

        int totals = otherFeeTypeService.count(OtherFeeType.class);
        if (totals > 0) {

            List<OtherFeeType> otherFeeTypes = otherFeeTypeService.listByPage(OtherFeeType.class, page.with(totals));

            modelAndView.addObject("otherFeeTypes", otherFeeTypes);
            modelAndView.addObject("page", page);

        }

        return modelAndView;
        
    }

    /**
     * 输出当前页记录/输出所有记录
     * 
     * @param page
     * @return
     */
    @RequestMapping(value = "/export", method = RequestMethod.GET)
    public ModelAndView export(Page page) {

        ModelAndView modelAndView = new ModelAndView(new ExcelTemplateView("data/business/other-fee-type-export.xlsx"));

        // 1. list result
        int totals = otherFeeTypeService.count(OtherFeeType.class);
        if (totals > 0) {
            List<OtherFeeType> otherFeeTypes = otherFeeTypeService.listByPage(OtherFeeType.class, page.with(totals));
            modelAndView.addObject("otherFeeTypes", otherFeeTypes);
        }

        // 2. format util
        FormatUtils fmt = new FormatUtils();
        modelAndView.addObject("fmt", fmt);

        return modelAndView;
        
    }
    
}
